<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:5px;">
    <fieldset class="layui-elem-field layui-field-title">
    </fieldset>
    <h2 style="text-align: center;margin-top: 10px;">您当前登录的组织架构在校区之上</h2>
    <div style="text-align: center;margin-top: 10px;">请选择签约校区！</div>
    <form class="layui-form" style="text-align: center;margin-top: 10px;">
        <div class="layui-input-inline">
            <select name="campus" lay-search="" lay-verify="required">
                <option value="">请选择签约校区</option>
                {volist name="campus" id="v"}
                <option value="{$v.id}">{$v['campus_name']}</option>
                {/volist}
            </select>
        </div>
    <fieldset class="layui-elem-field layui-field-title">
    </fieldset>
    <div style="text-align: center;margin-top: 10px;">
        <input class="layui-btn layui-btn-normal" lay-submit lay-filter="form" value="确定" readonly>
    </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    layui.use(['element', 'jquery', 'form', 'laydate', 'layer'], function () {
        let $ = layui.$,
            layer = layui.layer,
            element = layui.element,
            form = layui.form;

        let ids = '{$ids}';
        let user_id = '{$user_id}';
        let user_status = '{$user_status}';
        let status = '{$status}';
        console.log(ids);
        //监听提交
        form.on('submit(form)', function (data) {
            console.log(data);
            //发异步，把数据提交给php
            let field = data.field;
            let isLoad;
            $.ajax({
                url: '/admin/customer/close',
                method: "post",
                beforeSend: function () {

                },
                success: function (result) {
                    if (result.code === 1) {
                        if(user_status == 1){
                            field.ids = ids;
                            field.user_id = user_id;
                            field.campus_id = field.campus;
                            $.ajax({
                                url: '{:url("Customer/assignment")}',
                                method: "post",
                                data: field,
                                success: function (result) {
                                    layer.msg(result.msg);
                                    if (result.code === 1) {
                                        if(status == 1){
                                            parent.location.href = '{:url("Enrollment/lists")}';
                                        }else{
                                            parent.location.href = '{:url("Customer/lists")}';
                                        }

                                    }
                                },
                                complete: function () {
                                    layer.close(isLoad)
                                },
                                error: function (error) {
                                    console.log(error)
                                }
                            });
                        }else if(user_status == 2){
                            field.ids = ids;
                            field.user_id = user_id;
                            field.campus_id = field.campus;
                            $.ajax({
                                url: '{:url("Customer/receive_customer")}',
                                method: "post",
                                data: field,
                                success: function (result) {
                                    layer.msg(result.msg);
                                    if (result.code === 1) {
                                        parent.location.href = '{:url("Customer/lists")}';
                                    }
                                },
                                complete: function () {
                                    layer.close(isLoad)
                                },
                                error: function (error) {
                                    console.log(error)
                                }
                            });
                        }else if(user_status == 3){

                            field.ids = ids;
                            field.user_id = user_id;
                            field.campus_id = field.campus;
                            $.ajax({
                                url: '{:url("Student/assignment")}',
                                method: "post",
                                data: field,
                                success: function (result) {
                                    layer.msg(result.msg);
                                    if (result.code === 1) {
                                        parent.location.href = '{:url("Student/lists")}';
                                    }
                                },
                                complete: function () {
                                    layer.close(isLoad)
                                },
                                error: function (error) {
                                    console.log(error)
                                }
                            });

                        }else{
                            $.ajax({
                                url: '{:url("Customer/campus")}?type=' + '{$type}',
                                method: "post",
                                data: field,
                                success: function (result) {
                                    if (result.code === 1) {
                                        parent.location.href = result.url;
                                    }
                                },
                                complete: function () {
                                    layer.close(isLoad)
                                },
                                error: function (error) {
                                    console.log(error)
                                }
                            });
                        }
                        return false;
                    }
                },
            });
        });
    });
</script>
